package com.edu.exam.entity.assessment.technical;

import com.edu.exam.enums.assessment.technical.QuestionOperationType;
import com.edu.exam.enums.assessment.technical.QuestionOperationResult;
import com.edu.exam.enums.assessment.technical.QuestionApprovalStatus;
import com.edu.exam.enums.assessment.technical.RiskLevel;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 试卷查重历史实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：question_check_history
 *
 * 根据B-03-10试卷查重子模块设计文档实现
 * 存储试卷查重操作的历史记录，支持完整的操作审计和变更追踪。
 *
 * @author System
 * @version 1.0.0
 */

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class QuestionCheckHistory {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 查重记录ID
     */
    @Column(name = "record_id")
    private Long recordId;

    /**
     * 批量任务ID
     */
    @Column(name = "task_id", length = 50)
    private String taskId;

    /**
     * 试卷ID
     */
    @Column(name = "paper_id")
    private Long paperId;

    /**
     * 试卷标题
     */
    @Column(name = "paper_title", length = 200)
    private String paperTitle;

    /**
     * 操作类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_type", nullable = false, length = 20)
    private QuestionOperationType operationType;

    /**
     * 操作结果
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_result", nullable = false, length = 20)
    private QuestionOperationResult operationResult;

    /**
     * 操作前的相似度
     */
    @Column(name = "previous_similarity", precision = 5, scale = 4)
    private Double previousSimilarity;

    /**
     * 操作后的相似度
     */
    @Column(name = "new_similarity", precision = 5, scale = 4)
    private Double newSimilarity;

    /**
     * 相似度变化值
     */
    @Column(name = "similarity_change", precision = 5, scale = 4)
    private Double similarityChange;

    /**
     * 操作详细内容（JSON格式存储）
     */
    @Column(name = "operation_details", columnDefinition = "TEXT")
    private String operationDetails;

    /**
     * 变更原因说明
     */
    @Column(name = "change_reason", length = 500)
    private String changeReason;

    /**
     * 操作人员ID
     */
    @Column(name = "operator_id", length = 50)
    private Long operatorId;

    /**
     * 操作人员姓名
     */
    @Column(name = "operator_name", length = 100)
    private String operatorName;

    /**
     * 操作人员IP地址
     */
    @Column(name = "operator_ip", length = 45)
    private String operatorIp;

    /**
     * 用户代理信息
     */
    @Column(name = "user_agent", length = 500)
    private String userAgent;

    /**
     * 操作执行时间
     */
    @Column(name = "operation_time", nullable = false)
    private LocalDateTime operationTime;

    /**
     * 用户会话ID
     */
    @Column(name = "session_id", length = 100)
    private String sessionId;

    /**
     * 请求唯一标识
     */
    @Column(name = "request_id", length = 100)
    private String requestId;

    /**
     * 操作耗时（毫秒）
     */
    @Column(name = "operation_duration")
    private Long operationDuration;

    /**
     * 是否敏感操作
     */
    @Column(name = "is_sensitive_operation")
    private Boolean isSensitiveOperation = false;

    /**
     * 风险等级
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "risk_level", length = 20)
    private RiskLevel riskLevel;

    /**
     * 审批状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "approval_status", length = 20)
    private QuestionApprovalStatus approvalStatus;

    /**
     * 审批人ID
     */
    @Column(name = "approver_id", length = 50)
    private Long approverId;

    /**
     * 审批人姓名
     */
    @Column(name = "approver_name", length = 100)
    private String approverName;

    /**
     * 审批时间
     */
    @Column(name = "approval_time")
    private LocalDateTime approvalTime;

    /**
     * 审批意见
     */
    @Column(name = "approval_comment", length = 500)
    private String approvalComment;

    /**
     * 关联的外部系统ID
     */
    @Column(name = "external_system_id", length = 100)
    private String externalSystemId;

    /**
     * 外部系统名称
     */
    @Column(name = "external_system_name", length = 100)
    private String externalSystemName;

    /**
     * 备注信息
     */
    @Column(name = "remarks", length = 1000)
    private String remarks;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    /**
     * 版本号（用于乐观锁）
     */
    @Version
    @Column(name = "version", nullable = false)
    private Long version = 0L;

    /**
     * 删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;

    // 枚举定义

    }